package org.jeecg.modules.renlzpsxt.service.impl;

import org.jeecg.modules.renlzpsxt.entity.AgRenlzpsxt;
import org.jeecg.modules.renlzpsxt.entity.AgRenlzpsxtGuaid;
import org.jeecg.modules.renlzpsxt.mapper.AgRenlzpsxtGuaidMapper;
import org.jeecg.modules.renlzpsxt.mapper.AgRenlzpsxtMapper;
import org.jeecg.modules.renlzpsxt.service.IAgRenlzpsxtService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.List;
import java.util.Collection;

/**
 * @Description: 人脸抓拍摄像头
 * @Author: jeecg-boot
 * @Date:   2020-11-20
 * @Version: V1.0
 */
@Service
public class AgRenlzpsxtServiceImpl extends ServiceImpl<AgRenlzpsxtMapper, AgRenlzpsxt> implements IAgRenlzpsxtService {

	@Autowired
	private AgRenlzpsxtMapper agRenlzpsxtMapper;
	@Autowired
	private AgRenlzpsxtGuaidMapper agRenlzpsxtGuaidMapper;
	
	@Override
	@Transactional
	public void saveMain(AgRenlzpsxt agRenlzpsxt, List<AgRenlzpsxtGuaid> agRenlzpsxtGuaidList) {
		agRenlzpsxtMapper.insert(agRenlzpsxt);
		if(agRenlzpsxtGuaidList!=null && agRenlzpsxtGuaidList.size()>0) {
			for(AgRenlzpsxtGuaid entity:agRenlzpsxtGuaidList) {
				//外键设置
				entity.setZhub(agRenlzpsxt.getId());
				agRenlzpsxtGuaidMapper.insert(entity);
			}
		}
	}

	@Override
	@Transactional
	public void updateMain(AgRenlzpsxt agRenlzpsxt,List<AgRenlzpsxtGuaid> agRenlzpsxtGuaidList) {
		agRenlzpsxtMapper.updateById(agRenlzpsxt);
		
		//1.先删除子表数据
		agRenlzpsxtGuaidMapper.deleteByMainId(agRenlzpsxt.getId());
		
		//2.子表数据重新插入
		if(agRenlzpsxtGuaidList!=null && agRenlzpsxtGuaidList.size()>0) {
			for(AgRenlzpsxtGuaid entity:agRenlzpsxtGuaidList) {
				//外键设置
				entity.setZhub(agRenlzpsxt.getId());
				agRenlzpsxtGuaidMapper.insert(entity);
			}
		}
	}

	@Override
	@Transactional
	public void delMain(String id) {
		agRenlzpsxtGuaidMapper.deleteByMainId(id);
		agRenlzpsxtMapper.deleteById(id);
	}

	@Override
	@Transactional
	public void delBatchMain(Collection<? extends Serializable> idList) {
		for(Serializable id:idList) {
			agRenlzpsxtGuaidMapper.deleteByMainId(id.toString());
			agRenlzpsxtMapper.deleteById(id);
		}
	}
	
}
